"""
设备管理服务
"""

from jlpay.services.base_service import BaseService
from jlpay.model.openmerch.device.device import (
    UnionPayCodeQueryRequest, UnionPayCodeQueryResponse,
    UnionPayCodeAddRequest, UnionPayCodeAddResponse,
    DeviceChangeRequest, DeviceChangeResponse,
    DeviceCancelRequest, DeviceCancelResponse,
    DeviceAddRequest, DeviceAddResponse,
    DeviceQueryRequest, DeviceQueryResponse
)


class DeviceService(BaseService):
    """设备管理服务类"""
    
    def __init__(self, config):
        """
        初始化设备管理服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的API_URL
        api_url = getattr(request_class, 'API_URL', '')
        return f"{base_url}{api_url}"
    
    def device_query(self, request: DeviceQueryRequest) -> DeviceQueryResponse:
        """
        终端查询
        
        Args:
            request: DeviceQueryRequest实例
            
        Returns:
            DeviceQueryResponse: 终端查询响应
        """
        return self.post(request, DeviceQueryResponse)
    
    def query_unionpay_code(self, request: UnionPayCodeQueryRequest) -> UnionPayCodeQueryResponse:
        """
        查询银联码
        
        Args:
            request: UnionPayCodeQueryRequest实例
            
        Returns:
            UnionPayCodeQueryResponse: 银联码查询响应
        """
        return self.post(request, UnionPayCodeQueryResponse)
    
    def add_unionpay_code(self, request: UnionPayCodeAddRequest) -> UnionPayCodeAddResponse:
        """
        添加银联码
        
        Args:
            request: UnionPayCodeAddRequest实例
            
        Returns:
            UnionPayCodeAddResponse: 银联码加机响应
        """
        return self.post(request, UnionPayCodeAddResponse)
    
    def change_device(self, request: DeviceChangeRequest) -> DeviceChangeResponse:
        """
        变更设备
        
        Args:
            request: DeviceChangeRequest实例
            
        Returns:
            DeviceChangeResponse: 设备变更响应
        """
        return self.post(request, DeviceChangeResponse)
    
    def cancel_device(self, request: DeviceCancelRequest) -> DeviceCancelResponse:
        """
        撤销设备
        
        Args:
            request: DeviceCancelRequest实例
            
        Returns:
            DeviceCancelResponse: 设备撤销响应
        """
        return self.post(request, DeviceCancelResponse)
    
    def add_device(self, request: DeviceAddRequest) -> DeviceAddResponse:
        """
        添加设备
        
        Args:
            request: DeviceAddRequest实例
            
        Returns:
            DeviceAddResponse: 设备添加响应
        """
        return self.post(request, DeviceAddResponse) 